<!DOCTYPE html>
<html>
<head>
<title>考试.html</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<script src="resources/scripts/jquery-1.7.1.min.js"></script>
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<style type="text/css">
body {
	background: rgb(246, 248, 249);
	background: url('images/考试/bg.jpg') no-repeat center fixed;
	background-attachment: fixed;
	background-size: 100% 100%;
	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/考试/bg.jpg',
		sizingMethod='scale');
	background-repeat: no-repeat;
	background-positon: 100%, 100%;
	font: normal 12px tahoma, arial, verdana, sans-serif;
	margin: 0;
	padding: 0;
	border: 0 none;
	height: 100%;
}

.tt {
	text-align: left;
	font-size: 18px;
	line-height: 28px;
	margin-top: 8px;
}

#root {
	text-align: center;
}

#tb {
	margin: 0 auto;
	margin-top: 10%;
}

.bt {
	background-color: #3f89ec;
	width: 184px;
	height: 39px;;
	font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
	font-size: 25px;
	color: aliceblue;
}

.bt:HOVER {
	background-color: #0000ec;
	width: 184px;
	height: 39px;;
	font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
	font-size: 25px;
	color: aliceblue;
}

.radiotd {
	text-align: left;
	line-height: 30px;
	font-size: 16px;
	width: 50px;
}
</style>
<script type="text/javascript">
	window.onload = timedCount;
	var c = 1000;
	var t;
	function timedCount() {
		document.getElementById('txt').value = c;
		c = c - 1;
		t = setTimeout("timedCount()", 5);
		if (c == 0) {
			submitf();
			$("#txt").hide();
		}
	}
	function stopCount() {
		clearTimeout(t);
	}
</script>
<script type="text/javascript">
	var questions = new Array();
	$(document).ready(function() {

		getQestions();
		$("#button").click(submit);
	});

	function submit() {
		if (confirm("确定提交吗？请仔细检查")) {
			var rightnum = 0;
			for (var i = 0; i < questions.length; i++) {
				var name = "qs" + i;
				var answer = $('input[name=' + name + ']:checked').val();
				if (answer == parseFloat(questions[i].tanswer).toFixed(2)) {
					rightnum++;
				} else {
					$("#question" + i + "").css("color", "red");
				}
			}
			alert("您的成绩为：" + rightnum * 100 / questions.length);
		} else {
			return false;
		}
	}
	function submitf() {

		var rightnum = 0;
		for (var i = 0; i < questions.length; i++) {
			var name = "qs" + i;
			var answer = $('input[name=' + name + ']:checked').val();
			if (answer == parseFloat(questions[i].tanswer).toFixed(2)) {
				rightnum++;
			} else {
				$("#question" + i + "").css("color", "red");
			}
		}
		alert("您的成绩为：" + rightnum * 100 / questions.length);

	}
	function GetRandomNum(Min, Max) {
		var Range = Max - Min;
		var Rand = Math.random();
		while (Min + Math.round(Rand * Range) == 0) {
			Rand = Math.random();
		}
		return (Min + Math.round(Rand * Range));
	}
	function GetRandomNum2(Min, Max) {
		var Range = Max - Min;
		var Rand = Math.random();
		Rand = Math.random();
		return (Min + Math.round(Rand * Range));
	}
	function getQestions() {
		$
				.ajax({
					type : "GET",
					url : "../test/get",
					dataType : "json",
					contentType : "application/json",
					success : function(data) {

						var list = data.qList;
						for (var i = 0; i < list.length; i++) {
							questions[i] = list[i];
						}
						var html = "", j;
						var answer = new Array();
						// 				for (var i = 0; i < 100; i++) {
						// 				alert(GetRandomNum(-20, 20))

						// 				}
						for (var i = 0; i < questions.length; i++) {

							j = i + 1;
							answer[0] = (parseFloat(questions[i].tanswer) + parseInt(GetRandomNum(
									-20, 20))).toFixed(2);
							answer[1] = (parseFloat(questions[i].tanswer) + parseInt(GetRandomNum(
									-20, 20))).toFixed(2);
							answer[2] = (parseFloat(questions[i].tanswer) + parseInt(GetRandomNum(
									-20, 20))).toFixed(2);
							answer[3] = (parseFloat(questions[i].tanswer) + parseInt(GetRandomNum(
									-20, 20))).toFixed(2);
							var q = GetRandomNum2(0, 3);
							answer[q] = parseFloat(questions[i].tanswer)
									.toFixed(2);
							html = html
									+ "<tr><td colspan='3' id='question"+i+"' class='tt'>第"
									+ j + "题、" + questions[i].qdetail
									+ "=</td></tr>";
							html = html
									+ "<tr>"
									+ "<td ><input class='radiotd' name='qs"+i+"' type='radio' value="+answer[0]+">"
									+ answer[0]
									+ "</input></td>"
									+ "<td ><input class='radiotd' name='qs"+i+"' type='radio' value="+answer[1]+">"
									+ answer[1]
									+ "</input></td>"
									+ "<td ><input class='radiotd' name='qs"+i+"' type='radio' value="+answer[2]+">"
									+ answer[2]
									+ "</input></td>"
									+ "<td><input class='radiotd' name='qs"+i+"' type='radio' value="+answer[3]+">"
									+ answer[3] + "</input></td>" + "</tr>";

						}
						$("#tb").html(html);
						$("#button").show();
						$("#txt").show();
					}

				});
	}
</script>
</head>

<body>
	<div id="root">
		<table id="tb">
		</table>
		<div>
			<input type="submit" id="button" class="bt" value="提交试卷"
				hidden="hidden" /> <input type="text" id="txt" hidden="hidden">
		</div>
	</div>
</body>
</html>
